Skip to content

add a connection handler pool #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open

add a connection handler pool #36

wants to merge 26 commits into from

Conversation

rklaehn
Copy link
Contributor

@rklaehn rklaehn commented Jun 26, 2025

This is a compromise that tries to provide a connection pool even though iroh/quinn design does not make this easy. Connections are Clone, but they want to be owned by the pool. So you get a chance to work with a connection but are not supposed to clone them out.

Questions:

Does the thing in the main actor have to be a JoinSet, or could it also just be a FuturesUnordered?
Do we need a way to watch currently active and idle connections?

So far no tests or anything, just to put it somewhere.
@rklaehn
Copy link
Contributor Author

rklaehn commented Jun 26, 2025

CC @b5, we talked about this. Something like this is useful for normal connections, but essential to deal with the situation where you want 0rtt connections for occasional short lived interactions and then flip to keeping the connection around if the interactions become more frequent.

@n0bot n0bot bot added this to iroh Jun 26, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Jun 26, 2025
@rklaehn
Copy link
Contributor Author

rklaehn commented Aug 20, 2025

The original approach turns the connection pool into a combination of connection pool and task runner, and also is very unergonomic. So I ended up doing the following:

There is a ConnectionRef which impls Deref but has an additional field that tracks lifetime of the ConnectionRef. You must keep the ConnectionRef alive while you are using the connection in any way, but there is no way around this short of completely changing quinn. When no more ConnectionRefs are used, the connection goes into idle state. After an idle timeout, it gets closed.

If there is a demand for more connections before idle connections are closed, one of the idle connections (the oldest) is reclaimed. If there are no idle connections, and you are at capacity, you get an error.

There is currently no way to get notified when connection slots are available. We could change this by making some statistics (e.g. total number of connections and number of idle connections) available via a n0_watcher::Watchable.

@rklaehn rklaehn changed the title WIP: add a connection handler pool add a connection handler pool Aug 20, 2025
@rklaehn rklaehn requested a review from matheus23 August 20, 2025 13:12
we don't expect connect to panic, so we don't need to isolate it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

1 participant